package com.daveclay.boilermaker.web.providers

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.google.inject.Singleton
import javax.ws.rs.Consumes
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType
import javax.ws.rs.ext.Provider

@Singleton
@Provider
@Consumes(Array(MediaType.APPLICATION_JSON, "application/json", "text/json"))
@Produces(Array(MediaType.APPLICATION_JSON, "application/json", "text/json"))
class JacksonScalaContextResolver extends JacksonJaxbJsonProvider(JacksonScalaContextResolver.getObjectMapper, JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS)

object JacksonScalaContextResolver {

    def getObjectMapper = {
        val mapper = new ObjectMapper
        mapper.registerModule(new DefaultScalaModule)
        mapper
    }
}